package com.hp.bon.sgw.wh.channel;

import cn.chinatelecom.sgw.soap.SGWService;
import cn.chinatelecom.sgw.soap.SgwQueryAck;
import cn.chinatelecom.sgw.soap.SgwQueryReq;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.hp.bon.sgw.Constants.NodeStatus;
import com.hp.bon.sgw.bean.ProtocalConvertResult;
import com.hp.bon.sgw.bean.XmlMessage;
import com.hp.bon.sgw.convert.DataExchangerImpl;
import com.hp.bon.sgw.core.BuzProcessorManager;
import com.hp.bon.sgw.core.CallParam;
import com.hp.bon.sgw.core.InprogressMessageQueue;
import com.hp.bon.sgw.core.channel.IChannel;
import com.hp.bon.sgw.domain.Node;
import com.hp.bon.sgw.domain.SGWChannel;
import com.hp.bon.sgw.service.ConfigListener;
import com.hp.bon.sgw.service.ConfigService;
import com.hp.bon.sgw.service.RSASignService;
import com.hp.bon.sgw.start.SpringContext;
import com.hp.bon.sgw.util.Comutils;
import com.hp.bon.sgw.util.LogTool;
import com.hp.bon.sgw.util.RSAUtil;
import com.hp.bon.sgw.util.dcc.DccAvpHelper;
import com.hp.bon.sgw.wh.channel.handler.*;
import com.hp.bon.sgw.wh.service.UserResourceConfigService;
import com.hp.bon.sgw.wh.service.WHConfigService;
import com.hp.bon.sgw.wh.util.DateUtil;
import com.hp.bon.sgw.wh.utils.ResultCodeUtil;
import com.hp.ocs.diameter.DiameterUtils;
import com.hp.ocs.diameter.message.AVP;
import com.hp.ocs.diameter.message.Message;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.core.Container;
import org.simpleframework.http.core.ContainerProcessor;
import org.simpleframework.http.core.ContainerSelector;
import org.simpleframework.http.core.ContainerServer;
import org.simpleframework.transport.connect.Connection;
import org.simpleframework.transport.connect.SocketConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLInputFactory;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;

import static com.hp.bon.sgw.Constants.LOG;

public class HBCFQChannel_QryBill implements Container, ConfigListener, IChannel {
	private static final Logger logger = LoggerFactory.getLogger(HBCFQChannel_QryBill.class);
	static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	protected ConfigService confSrv;
	private WHConfigService whConfigService;
	private UserResourceConfigService userResourceConfigService ;
	private int maxLinkCount;
	static JAXBContext jc = null;
	private String cfqReqPath = "/CreditProdFee";// 橙分期查询
	private String qryBalanceRecord = "/QryBalanceRecord"; // 余额变动汇总查询查询
	private String qryReturnBalanceDetail = "/QryReturnBalanceDetail"; // 话费返还记录查询--DCC
	private String qryReturnBalanceInfoDetail = "/QryReturnBalanceInfoDetail"; // 话费返还记录明细查询API
	private String QryCustBill = "/QryCustBill"; // 帐单查询
	private String AccuUseQry = "/AccuUseQry"; // 量本使用情况查询
	private String AccuUseDetailQry = "/AccuUseDetailQry"; // 量本使用明细情况查询
	private String QueryBalance = "/QueryBalance"; // 余额查询。根据用户号码、用户标识、帐户标识等条件进行可用余额明细查询，返回余额明细信息的列表
	private String AcctPaymentUndo = "/AcctPaymentUndo"; // 帐务能力中心返销接口（根据缴费流水进行返销操作）
	private String RtBillItem = "/RtBillItem"; //  3.2.9	4.3.1.2.4	详单查询(下游DCC+webservice接口)
	private String QryInstantFeeList = "/QryInstantFeeList"; // 3.2.10 实时话费明细查询
	private String QryBill = "/QryBill"; // 3.2.11.1欠费查询API
	private String QryPayment = "/QryPayment";//3.2.12.1缴费销帐记录查询API
	private String QryBalanceRecordDetail = "/QryBalanceRecordDetail";
	private String ImeiInfo="/imeiInfo";// 5G入网提醒
	//数据库直连
	private String QryBalanceModifyLog = "/QryBalanceModifyLog"; // 帐本变更信息查询
	private String QryTax = "/QryTax"; // 增值税查询
	private String balance = "/balance/"; // 3.3.3.1查询余额详情API
	private String balanceList = "/balance";//3.3.4.1查询余额列表API
	private String balanceType = "/balanceType/"; // 3.3.5.1查询余额帐本类型详情API
	private String balanceTypeList = "/balanceType"; //3.3.6.1查询余额帐本类型列表API
	private String paymentMethod="/paymentMethod/";//查询付款方式详情
	private String paymentMethodList="/paymentMethod";// 查询付款方式列表
	private String acctItemType="/acctItemType/";//查询帐目类型详情
	private String acctItemTypeList="/acctItemType";// 查询帐目类型列表
	private String taxItem="/taxItem/";//查询税目详情
	private String taxItemList="/taxItem";//查询税目列表
	private String depositType="/depositType/";//查询押金类型详情
	private String depositTypeList="/depositType";// 查询押金类型列表
	private ContainerServer server = null;
	protected RSASignService rsaSignService;
	static XMLInputFactory inputFactory = XMLInputFactory.newInstance();

	protected final Set<String> monitorConfKeys = new HashSet<String>();
	private SGWChannel channel;
	ThreadPoolExecutor executor;
	ThreadPoolExecutor collector;

	static {
		try {
			jc = JAXBContext.newInstance("cn.chinatelecom.sgw.soap");
		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

	public HBCFQChannel_QryBill(SGWChannel channel) {
		this.channel = channel;
		this.confSrv = SpringContext.getInstance().getConfigService();
		this.confSrv.addConfigListener(this);
		this.whConfigService = SpringContext.getApplicationContext().getBean(WHConfigService.class);
		// Timer _timer = new Timer("DelayTask-" + channel.toString(), true);
		// _timer.schedule(new DelayTask(), 1000L, 1000L);
	}

	public void start() {
		logger.info("start HBCFQChannel channel:" + this.channel.toString() + " ...");
		this.monitorConfKeys.add("business.max_conn");
		loadParams();
		String key = "sgw.webserver.thread.max";
		int maxThreads = this.confSrv.getIntValue(key, 50);
		logger.info(key + " :" + maxThreads);
		String endPoint = this.channel.getUri();
		if (endPoint == null) {
			logger.warn("channel dont't defined ws addr");
			return;
		}
		logger.info("start sgw HBCFQChannel server portal at " + endPoint);

		try {
			URL srvURL = new URL(endPoint);
			int port = srvURL.getPort();
			// 找不到端口就启动失败
			if (port == -1) {
				logger.info("start HBCFQChannel error : port Not defined");
				return;
			}
			String host = srvURL.getHost();
			if (host.equals("127.0.0.1") || host.equalsIgnoreCase("localhost")) {
				host = "0.0.0.0";
			}
			server = new ContainerServer(this, maxThreads);

			Connection connection = new SocketConnection(server);
			SocketAddress address = new InetSocketAddress(host, port);
			connection.connect(address);
			collector = ((ContainerSelector) ((ContainerProcessor) server.getProcessor()).getSelector()).getCollect().getQueue();
			executor = ((ContainerSelector) ((ContainerProcessor) server.getProcessor()).getSelector()).getExecutor().getQueue();

			// connectionManager = new MultiThreadedHttpConnectionManager();
			// // ... configure connectionManager ...
			// httpClient = new HttpClient(connectionManager);
			// httpClient.getHttpConnectionManager().getParams()
			// .setConnectionTimeout(10000);
			// httpClient.getHttpConnectionManager().getParams()
			// .setSoTimeout(45000);

			this.channel.setStatus(NodeStatus.ON_LINE);
			confSrv.updateChannelStatus2DB(this.channel.getId(), NodeStatus.ON_LINE);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("start HBCFQChannel " + this.channel.toString() + " err " + e);
		}
	}

	@Override
	public void handle(Request request, Response response) {
		long receiveTime = System.currentTimeMillis();
		PrintStream body = null;
		try {
			body = response.getPrintStream();
			// ContentType cntType = request.getContentType();
			// if (cntType == null) {
			// body.println("invalid request Content type is null");
			// body.close();
			// return;
			// }
			// cntType.setCharset(Comutils.fixContentCharSet(cntType.getCharset()));
			String reqContent = request.getContent();
			if (logger.isInfoEnabled()) {
				logger.info("http request from " + request.getClientAddress() + ", " + request.getPath().getPath() + "\r\n" + reqContent);
			}

			String reqPath = request.getPath().getPath();
			if (reqPath.endsWith(cfqReqPath)) {// 橙分期查询
				dealCfqReqPath(request, response, body, receiveTime);
			} else if (reqPath.endsWith(qryReturnBalanceDetail)) {// 话费返还记录查询--DCC
				dealQryBalanceDetail(request, response, body, receiveTime);
			} else if (reqPath.endsWith(qryReturnBalanceInfoDetail)) {// 话费返还记录明细查询API
				qryReturnBalanceInfoDetail(request, response, body, receiveTime);
			} else if (reqPath.endsWith(qryBalanceRecord)) {// 余额变动汇总查询查询
				dealQryBalanceRecord(request, response, body, receiveTime);
			} else if (reqPath.endsWith(QryCustBill)) { // 帐单查询
				dealQryCustBill(request, response, body, receiveTime);
			} else if (reqPath.endsWith(AcctPaymentUndo)) {// 帐务能力中心返销接口（根据缴费流水进行返销操作）
				dealAcctPaymentUndo(request, response, body, receiveTime);
			} else if (reqPath.endsWith(QryBalanceModifyLog)) {//// 帐本变更信息查询
				dealQryBalanceModifyLog(request, response, body, receiveTime);
			} else if (reqPath.endsWith(QryTax)) {// 增值税查询
				dealQryTax(request, response, body, receiveTime);
			} else if (reqPath.endsWith(AccuUseQry)) {// 量本使用情况查询
				dealAccuUseQry(request, response, body, receiveTime);
			} else if (reqPath.endsWith(AccuUseDetailQry)) { // 量本使用明细情况查询
				dealAccuUseDetailQry(request, response, body, receiveTime);
			} else if (reqPath.endsWith(QueryBalance)) {// 余额查询// 根据用户号码、用户标识、帐户标识等条件进行可用余额明细查询，返回余额明细信息的列表
				dealQueryBalance(request, response, body, receiveTime);
			}else if (reqPath.endsWith( RtBillItem)) {//详单查询(下游DCC+webservice接口)
				dealRtBillItem(request, response, body, receiveTime);
			}else if(reqPath.endsWith( QryInstantFeeList)){
				delQryInstantFeeList(request, response, body, receiveTime);
			}else if(reqPath.endsWith( QryBill)) {
				dealQryBill(request, response, body, receiveTime);
			}else if(reqPath.endsWith( QryPayment)) {
				dealQryPayment(request, response, body, receiveTime);
			}else if(reqPath.endsWith( QryBalanceRecordDetail)) {
				dealQryBalanceRecordDetail(request, response, body, receiveTime);
			}else if(reqPath.endsWith(ImeiInfo)) {
				dealImeiInfo(request, response, body, receiveTime);
			} if(reqPath.contains( balanceType) || reqPath.endsWith( balanceTypeList)) {
				dealBalanceType(request, response, body, receiveTime);
			}else if(reqPath.contains( balance) || reqPath.endsWith( balanceList)) {
				dealBalance(request, response, body, receiveTime);
			}else if(reqPath.contains( paymentMethod) || reqPath.endsWith(paymentMethodList)) { 
				dealPaymentMethod(request, response, body,receiveTime); 
			}else if(reqPath.contains( acctItemType) || reqPath.endsWith(acctItemTypeList)) { 
				dealAcctItemType(request, response,body, receiveTime); 
			}else if(reqPath.contains( taxItem) || reqPath.endsWith(taxItemList)) { 
				dealTaxItem(request, response, body, receiveTime); 
			}else if(reqPath.contains( depositType) || reqPath.endsWith( depositTypeList)) { 
				dealDepositType(request, response, body, receiveTime); 
			}
				 
			
		} catch (Exception e) {
			logger.warn("http request err:", e);
			if (body != null) {
				body.println("Server error :" + e.toString());
				body.close();
			}
		}
	}
	
	

	/**
	 * 详单查询(下游DCC+webservice接口)
	 * 
	 * @param request
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealRtBillItem(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 详单查询(下游DCC+webservice接口)add by zhoumy 20190703
		logger.info("start dealRtBillItem......");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Server", "HB SGW SERVER )");
		response.setDate("Date", receiveTime);
		response.setDate("Last-Modified", receiveTime);

		String value = request.getValue("X-CTG-Request-ID");
		response.set("X-CTG-Request-ID", value);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");

		if (!"POST".equals(request.getMethod())) {
			Map<String, String> data = new HashMap<String, String>();
			data.put("resultCode", "01");
			data.put("resultMsg", "http请求方式错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		try {
			String billingCycleId = JSON.parseObject(content).getString("billingCycleId");
			String startDate = JSON.parseObject(content).getString("startDate");
			String endDate = JSON.parseObject(content).getString("endDate");
			
			if(StringUtils.isBlank(JSON.parseObject(content).getJSONObject("svcObjectStruct").getString("objValue")) || StringUtils.isBlank(billingCycleId)) {
				throw new Exception();
			}
			Map<String, String> data = new HashMap<String, String>();
			int isOut=0;
			if(billingCycleId.length() != 6) {
				data.put("resultCode", "1203");
				data.put("resultMsg", "帐期格式不对");
				isOut=1;
			}else {
				SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");
				Date billDate = null;
				try {
					billDate = sdf.parse(billingCycleId);
				}catch (Exception e) {
					data.put("resultCode", "1203");
					data.put("resultMsg", "帐期格式不对");
					isOut=1;
				}
				if(isOut == 0) {
					
					Date date1 = DateUtil.addYear(new Date(), -1);
					if(DateUtil.isDateBefore(billDate, date1) || DateUtil.isDateBefore(new Date(), billDate) ) {
						data.put("resultCode", "1301");
						data.put("resultMsg", "帐期超过查询时间范围");
						isOut = 1;
					}
				}
			}
			if(isOut != 0) {
				Gson gson = new Gson();
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
		}catch (Exception e) {
			Map<String, String> data = new HashMap<String, String>();
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
//		if (content == null || "".equals(content)) {
//			Map<String, String> data = new HashMap<String, String>();
//			data.put("resultCode", "01");
//			data.put("resultMsg", "输入参数解析错误");
//			Gson gson = new Gson();
//			String respXML = gson.toJson(data);
//			byte[] resp = respXML.getBytes("UTF-8");
//			body.write(resp);
//			body.close();
//			return;
//		}
		JSONObject jsonObject = JSONObject.parseObject(content);
		Element serviceInformation = DocumentHelper.createElement("Service_Information");
		serviceInformation.addElement("ValueType").setText("1");//查询值类型：1-业务号码；2-客户标识；3-合同号标识
		serviceInformation.addElement("Value").setText((jsonObject.getJSONObject("svcObjectStruct")).get("objValue") + "");//查询值 
		serviceInformation.addElement("Area_Code").setText("");//电话区号 0710 襄樊
		serviceInformation.addElement("QueryType").setText("1");//查询类型（1查询最新记录、2查询所有记录） 1语音类详单、2短信类详单、3数据类详单、4增值类详单

		XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("QueryServ.HSS@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(serviceInformation.asXML());
		req.setDataElement(serviceInformation);
		// new CallParam对象
		YHJQHandle yhjqHandle = new YHJQHandle(body, jsonObject.getString("qryType"), whConfigService.getValue("XDCXURL", ""), 
				jsonObject.getString("startDate"), jsonObject.getString("endDate"));
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), yhjqHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	
	

	// 橙分期查询
	protected void dealCfqReqPath(Request request, Response response, PrintStream body, long receiveTime)
			throws Exception {
		// 查询号码指定账期费用 add by fengr 20190624
		logger.info("start ProdFee......");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Server", "HB SGW SERVER )");
		response.setDate("Date", receiveTime);
		response.setDate("Last-Modified", receiveTime);

		String value = request.getValue("X-CTG-Request-ID");
		response.set("X-CTG-Request-ID", value);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		
		
		String accNbr = request.getParameter("accNbr") == null ? "" : request.getParameter("accNbr");
		String billingCycleId = request.getParameter("billingCycleId") == null ? "" : request.getParameter("billingCycleId");

		// 入参校验
		if ("".equals(accNbr) || "".equals(billingCycleId)) {
			Map<String, String> data = new HashMap<String, String>();
			data.put("accNbr", "0");
			data.put("billingCycleId", "0");
			data.put("curFee", "0");
			data.put("sendFee", "0");
			data.put("roamFee", "0");
			data.put("spFee", "0");
			data.put("remark", "");
			data.put("resultCode", "01");
			data.put("resultMsg", "输入参数解析错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		// 手机号码格式校验
		if(!accNbr.matches("\\d{11}")){
			Map<String, String> data = new HashMap<String, String>();
			data.put("accNbr", "0");
			data.put("billingCycleId", "0");
			data.put("curFee", "0");
			data.put("sendFee", "0");
			data.put("roamFee", "0");
			data.put("spFee", "0");
			data.put("remark", "");
			data.put("resultCode", "01");
			data.put("resultMsg", "手机号码必须为11位");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		// billingCycleId必须为YYYYMM日期格式
		if(!billingCycleId.matches("\\d{6}")){
			Map<String, String> data = new HashMap<String, String>();
			data.put("accNbr", "0");
			data.put("billingCycleId", "0");
			data.put("curFee", "0");
			data.put("sendFee", "0");
			data.put("roamFee", "0");
			data.put("spFee", "0");
			data.put("remark", "");
			data.put("resultCode", "01");
			data.put("resultMsg", "帐期必须为YYYYMM格式");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		JSONObject jsonObject=new JSONObject();
		String jf3_flag = userResourceConfigService.getValue("jf3_flag","");////增加刷新开关  ,配置为1则表示启用割接地市判断，配置为0则表示按现有的流程
		jsonObject.put("jf3_flag", jf3_flag);
		jsonObject.put("jf3_latn_id", userResourceConfigService.getValue("jf3_latn_id",""));
		jsonObject.put("accNbr", accNbr);
		jsonObject.put("billingCycleId", billingCycleId);
		//新的
		Element serviceInformation_new = DocumentHelper.createElement("Service_Information");
		Element element_new = serviceInformation_new.addElement("Acc_Nbr");
		element_new.setText(accNbr);
		element_new = serviceInformation_new.addElement("Destination_Attr");
		element_new.setText("2");
		String asXML_new = serviceInformation_new.asXML();
		//jsonObject.put("serviceInformation_new", serviceInformation_new);
		//旧的
		Element serviceInformation_old = DocumentHelper.createElement("Service_Information");
		Element element_old = serviceInformation_old.addElement("Acc_Nbr");
		element_old.setText(accNbr);
		element_old = serviceInformation_old.addElement("Billing_Cycle");
		element_old.setText(billingCycleId);
		String asXML_old = serviceInformation_old.asXML();
		jsonObject.put("serviceInformation_old", serviceInformation_old);
		
		XmlMessage req = new XmlMessage(true);

		// String tmallHostId = whConfigService.getValue(AliParam.tmallHostId,
		// "HBCFQ@027.ctnbc-bon.net");
		// 定义橙分期HOST ID
		
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("1".equals(jf3_flag) ? "QueryHomeAreaByAccNbr.HSS@027.ctnbc-bon.net" : "OrangeStageBill.Query@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA("1".equals(jf3_flag) ? asXML_new : asXML_old);
		req.setDataElement("1".equals(jf3_flag) ? serviceInformation_new : serviceInformation_old);
		jsonObject.put("req", req);
		// new CallParam对象
		HBCFQHandle hbcfqHandle = new HBCFQHandle(body,jsonObject);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), hbcfqHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}

	/**
	 * 帐务能力中心返销接口
	 * 
	 * @param request
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealAcctPaymentUndo(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 帐务能力中心返销接口 add by zhoumy 20190703
		logger.info("start dealAcctPaymentUndo......");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Server", "HB SGW SERVER )");
		response.setDate("Date", receiveTime);
		response.setDate("Last-Modified", receiveTime);

		String value = request.getValue("X-CTG-Request-ID");
		response.set("X-CTG-Request-ID", value);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");

		if (!"POST".equals(request.getMethod())) {
			Map<String, String> data = new HashMap<String, String>();
			data.put("newPaymentId", "0");
			data.put("resultCode", "01");
			data.put("resultMsg", "http请求方式错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();

		if (content == null || "".equals(content)) {
			Map<String, String> data = new HashMap<String, String>();
			data.put("newPaymentId", "0");
			data.put("resultCode", "01");
			data.put("resultMsg", "输入参数解析错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		JSONObject jsonObject = JSONObject.parseObject(content);

		Element serviceInformation = DocumentHelper.createElement("Service_Information");
		Element elementReverse = serviceInformation.addElement("Reverse");
		Element element = elementReverse.addElement("Serial_Type");// 流水类型：0表示付款流水、1表示销帐流水
		element.setText("1");
		element = elementReverse.addElement("Serial_Nbr");// 流水号 (填入参paymentId)
		element.setText(jsonObject.getString("paymentId"));
		element = elementReverse.addElement("Latn_Id");// 本地网区号 不传值
		element.setText("");

		XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PaymentReverse.Payment@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(serviceInformation.asXML());
		req.setDataElement(serviceInformation);
		ZWNLFXHandle yebdhzcxHandle = new ZWNLFXHandle(body);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), yebdhzcxHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);

	}

	/**
	 * 余额变动汇总查询查询
	 * 
	 * @param request
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQryBalanceRecord(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 帐本余额变动汇总查询 add by zhoumy 20190703
		logger.info("start dealQryBalanceRecord......");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Server", "HB SGW SERVER )");
		response.setDate("Date", receiveTime);
		response.setDate("Last-Modified", receiveTime);

		String value = request.getValue("X-CTG-Request-ID");
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============CTGRequestID:"+value);
		response.set("X-CTG-Request-ID", value);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");

		if (!"POST".equals(request.getMethod())) {
			Map<String, String> data = new HashMap<String, String>();
			data.put("balanceTypeFlag", "0");
			data.put("billingCycleId", "0");
			data.put("balanceBegin", "0");
			data.put("balanceIn", "0");
			data.put("balanceOut", "0");
			data.put("balanceEnd", "0");
			data.put("resultCode", "01");
			data.put("resultMsg", "http请求方式错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();

		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getJSONObject("svcObjectStruct").getString("objValue"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			Map<String, String> data = new HashMap<String, String>();
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		JSONObject jsonObject = JSONObject.parseObject(content);

		String objType = jsonObject.getJSONObject("svcObjectStruct").getString("objType");
		String objValue = jsonObject.getJSONObject("svcObjectStruct").getString("objValue");
		String objAttr = jsonObject.getJSONObject("svcObjectStruct").getString("objAttr");
		String dataArea = jsonObject.getJSONObject("svcObjectStruct").getString("dataArea");
		Element serviceInformation = null;
		String jf3_flag=userResourceConfigService.getValue("jf3_flag", "0");
        logger.info("=====================jf3_flag=================="+jf3_flag);
		if("1".equals(jf3_flag)) {
			//开关开,调用新流程
            logger.info("==============新流程入参=========================");
			String substring = objValue.substring(0, 1);
			String str = null; 
			if("1".equals(substring)) {
				str="027";
			}else if("0".equals(substring)) {
				str=objValue.substring(0, 3);
				if(!"027".equals(str)) {
					str=objValue.substring(0, 4);
				}
			}else if("6".equals(objAttr)){
                //天翼高清
                str="0"+objValue.substring(0, 3);
            }else{
                str="027";
            }
			serviceInformation = DocumentHelper.createElement("Service_Information");
			serviceInformation.addElement("Channel_Id").setText("200");
			serviceInformation.addElement("Area_Code").setText(str);
			serviceInformation.addElement("DestinationAttr").setText(objAttr);
			serviceInformation.addElement("Destination_Id").setText(objValue);
			serviceInformation.addElement("Destination_Id_Type").setText("2");
		}else {
            logger.info("==============旧流程入参=========================");
			//开关 关,旧流程
			serviceInformation = DocumentHelper.createElement("Service_Information");
			Element element = serviceInformation.addElement("Acc_Nbr");
			element.setText((jsonObject.getJSONObject("svcObjectStruct")).get("objValue") + "");
			element = serviceInformation.addElement("DestinationAttr");// 用户属性 0固话、1小灵通、2移动、3宽带、4智能公话、5互联星空、6天翼高清、99未知
			element.setText((jsonObject.getJSONObject("svcObjectStruct")).get("objAttr") + "");
			element = serviceInformation.addElement("Billing_Cycle");
			element.setText(jsonObject.get("billingCycleId") + "");
			element = serviceInformation.addElement("QueryType");
			element.setText("0");
		}
		XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("1".equals(jf3_flag) ? "ServAuth.jf3@027.ctnbc-bon.net" : "BalanceRecord.balanceYXHB9@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(serviceInformation.asXML());
		req.setDataElement(serviceInformation);
		YEBDHZCXHandle yebdhzcxHandle = new YEBDHZCXHandle(body, jsonObject.getString("balanceTypeFlag"),jsonObject,request,startTime);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), yebdhzcxHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
        long endTime = Calendar.getInstance().getTimeInMillis();
        String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("===session_id:"+value
                +"====recv_request_time:"+startDate
                +"====send_response_time:"+endDate
                +"====service_context_id:"+request.getPath().getPath()
                +"====访问时间差:"+(endTime-startTime));
	}
	

	/**
	 * 话费返还记录明细查询API
	 * 
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void qryReturnBalanceInfoDetail(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============CTGRequestID:"+CTGRequestID);
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/qryReturnBalanceInfoDetail");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null ) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getJSONObject("svcObjectStruct").getString("objValue"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		JSONObject jsonContent = JSON.parseObject(content);
		String objType = jsonContent.getJSONObject("svcObjectStruct").getString("objType");
		String objValue = jsonContent.getJSONObject("svcObjectStruct").getString("objValue");
		String objAttr = jsonContent.getJSONObject("svcObjectStruct").getString("objAttr");
		String dataArea = jsonContent.getJSONObject("svcObjectStruct").getString("dataArea");
		Element serviceInformation = null;
		String jf3_flag=userResourceConfigService.getValue("jf3_flag", "0");
        LOG.info("=============jf3_flag=============="+jf3_flag);
		if("1".equals(jf3_flag)) {
		    LOG.info("=============进入新流程数据加载==============");
			//开关开,调用新流程
			String substring = objValue.substring(0, 1);
			String str = null; 
			if("1".equals(substring)) {
				str="027";
			}else if("0".equals(substring)) {
				str=objValue.substring(0, 3);
				if(!"027".equals(str)) {
					str=objValue.substring(0, 4);
				}
			}else if("6".equals(objAttr)){
                //天翼高清
                str="0"+objValue.substring(0, 3);
            }else{
                str="027";
            }
			serviceInformation = DocumentHelper.createElement("Service_Information");
			serviceInformation.addElement("Channel_Id").setText("200");
			serviceInformation.addElement("Area_Code").setText(str);
			serviceInformation.addElement("DestinationAttr").setText(objAttr);
			serviceInformation.addElement("Destination_Id").setText(objValue);
			serviceInformation.addElement("Destination_Id_Type").setText("2");
		}else {
            LOG.info("=============进入旧流程数据加载==============");
			//开关 关,旧流程
			serviceInformation = DocumentHelper.createElement("Service_Information");
			Element balanceInformation = serviceInformation.addElement("Balance_Information");
			// 用户号码(如果是用户号码且用户属性为固话、宽带时，,此AVP取值要求带区号,含0
			balanceInformation.addElement("Destination_Id").setText(jsonContent.getJSONObject("svcObjectStruct").getString("objValue"));
			// 用户号码类型：2-用户号码
			balanceInformation.addElement("Destination_Id_Type").setText("2");
			// 用户属性（当号码类型为用户号码时填写）0-固话、1-、2-移动、3-宽带、4-智能公话、5-互联星空、6-天翼高清、99-未知
			balanceInformation.addElement("DestinationAttr").setText(objAttr);
			// 电话区号
			String Area_Code = "";
			if (!objValue.startsWith("0") || objValue.startsWith("027")) {
				Area_Code = "027";
			} else {
				Area_Code = objValue.substring(0, 4);
			}
			balanceInformation.addElement("Area_Code").setText(Area_Code);
			// 返还计划实例ID
			balanceInformation.addElement("ReturnPlanId").setText(jsonContent.getString("returnPlanId"));
			// 省内和集团方向区分标示，省内填默认值1
			balanceInformation.addElement("QueryType").setText("1");
		}
		XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("1".equals(jf3_flag) ? "ServAuth.jf3@027.ctnbc-bon.net" : "ReturnBalanceDetail.balanceYXHB9@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(serviceInformation.asXML());
		req.setDataElement(serviceInformation);
		jsonContent.put("IP", IP);
		// new CallParam对象
		ReturnBalanceInfoDetailHandle returnBalanceInfoDetailHandle = new ReturnBalanceInfoDetailHandle(body,jsonContent,request,startTime);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), returnBalanceInfoDetailHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
        long endTime = Calendar.getInstance().getTimeInMillis();
        String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("===session_id:"+CTGRequestID
                +"====recv_request_time:"+startDate
                +"====send_response_time:"+endDate
                +"====service_context_id:"+request.getPath().getPath()
                +"====访问时间差:"+(endTime-startTime));
	}

	/**
	 * 处理“话费返还记录查询--DCC”请求
	 * 
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQryBalanceDetail(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============CTGRequestID:"+CTGRequestID);
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QryReturnBalanceDetail");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getJSONObject("svcObjectStruct").getString("objValue"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		JSONObject jsonContent = JSON.parseObject(content);
		String objType = jsonContent.getJSONObject("svcObjectStruct").getString("objType");
		String objValue = jsonContent.getJSONObject("svcObjectStruct").getString("objValue");
		String objAttr = jsonContent.getJSONObject("svcObjectStruct").getString("objAttr");
		String dataArea = jsonContent.getJSONObject("svcObjectStruct").getString("dataArea");
		Element serviceInformation = null;
		String jf3_flag=userResourceConfigService.getValue("jf3_flag", "0");
		if("1".equals(jf3_flag)) {
		    LOG.info("==============进入新流程参数组建===========");
			//开关开,调用新流程
			String substring = objValue.substring(0, 1);
			String str = null; 
			if("1".equals(substring)) {
				str="027";
			}else if("0".equals(substring)) {
				str=objValue.substring(0, 3);
				if(!"027".equals(str)) {
					str=objValue.substring(0, 4);
				}
			}else if("6".equals(objAttr)){
                //天翼高清
                str="0"+objValue.substring(0, 3);
            }else{
                str="027";
            }
			serviceInformation = DocumentHelper.createElement("Service_Information");
			serviceInformation.addElement("Channel_Id").setText("200");
			serviceInformation.addElement("Area_Code").setText(str);
			serviceInformation.addElement("DestinationAttr").setText(objAttr);
			serviceInformation.addElement("Destination_Id").setText(objValue);
			serviceInformation.addElement("Destination_Id_Type").setText("2");
		}else {
            LOG.info("==============进入旧流程参数组建===========");
			//开关 关,旧流程
			serviceInformation = DocumentHelper.createElement("Service_Information");
			Element balanceInformation = serviceInformation.addElement("Balance_Information");
			// 用户号码(如果是用户号码且用户属性为固话、宽带时，,此AVP取值要求带区号,含0
			balanceInformation.addElement("Destination_Id").setText(jsonContent.getJSONObject("svcObjectStruct").getString("objValue"));
			// 用户号码类型：2-用户号码
			balanceInformation.addElement("Destination_Id_Type").setText(objAttr);
			// 用户属性（当号码类型为用户号码时填写）0-固话、1-、2-移动、3-宽带、4-智能公话、5-互联星空、6-天翼高清、99-未知
			balanceInformation.addElement("DestinationAttr").setText("2");
			// 电话区号
			String Area_Code = "";
			if (!objValue.startsWith("0") || objValue.startsWith("027")) {
				Area_Code = "027";
			} else {
				Area_Code = objValue.substring(0, 4);
			}
			balanceInformation.addElement("Area_Code").setText(Area_Code);
			// 查询业务类型（默认0）：0按帐户查询、1按用户查询
			balanceInformation.addElement("Query_Flag").setText(dataArea.equals("2")?"1":"0");
			// 省内和集团方向区分标示，省内填默认值1
			balanceInformation.addElement("QueryType").setText("1");
		}
		
		XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("1".equals(jf3_flag) ? "ServAuth.jf3@027.ctnbc-bon.net" : "ReturnBalance.balanceYXHB9@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(serviceInformation.asXML());
		req.setDataElement(serviceInformation);
		jsonContent.put("IP", IP);
		// new CallParam对象
		ReturnBalanceHandle returnBalanceHandle = new ReturnBalanceHandle(body,jsonContent,request,startTime);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), returnBalanceHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
        long endTime = Calendar.getInstance().getTimeInMillis();
        String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("===session_id:"+CTGRequestID
                +"====recv_request_time:"+startDate
                +"====send_response_time:"+endDate
                +"====service_context_id:"+request.getPath().getPath()
                +"====访问时间差:"+(endTime-startTime));
	}

	
	/**
	 * 查询客户历史帐单的服务 3.2.4 4.5.1.2.2 帐单查询(下游webservice)
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQryCustBill(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 查询客户历史帐单的服务 add by fengr 20190705
        logger.info("start dealQryCustBill......");
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
        logger.info("=============CTGRequestID:"+CTGRequestID);
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============startDate:"+startDate);
        response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QryCustBill");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getString("accNbr"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}

		JSONObject jsonContent = JSON.parseObject(content);
		String queryFlagStr = jsonContent.getString("queryFlag");
		String destinationAttrStr = jsonContent.getString("destinationAttr");
		String QueryFromStr = "216";
		String objIdStr = jsonContent.getString("accNbr");
		String billingCycleStr =  jsonContent.getString("billingCycle");
		if(StringUtils.isEmpty(billingCycleStr)){
			billingCycleStr = new SimpleDateFormat("yyyyMM").format(System.currentTimeMillis());
			jsonContent.put("billingCycle", billingCycleStr);
		}
		String buildStringMes = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.hquery.ailk.com/\">"
							+ "<soapenv:Header/>"
							+ "<soapenv:Body>"
							+ "<ws:CustBillJTQry>"
							+ "<param>"
							+ "{\"ObjType\":\"0\",\"ObjId\":\"" + objIdStr + "\",\"QryFlag\":\"" + queryFlagStr
							+ "\",\"BillMonth\":\"" + billingCycleStr + "\",\"DestinationAttr\":\"" + destinationAttrStr
							+ "\",\"QueryFrom\":\""+ QueryFromStr + "\"}"
							+ "</param>"
							+ "</ws:CustBillJTQry>"
							+ "</soapenv:Body>"
							+ "</soapenv:Envelope>";

		XmlMessage req = new XmlMessage(true);

		// 定义橙分期HOST ID
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("BillDetailQuery.BillYXHB9.NEW@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(buildStringMes.toString());
        jsonContent.put("jfStartTime", System.currentTimeMillis());
		// new CallParam对象
		QryCustBillHandle qryCustBillHandle = new QryCustBillHandle(body, jsonContent,startTime,request);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), qryCustBillHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
    }

	
	/**
	 * 3.2.5 4.3.1.2.4 量本使用查询(下游webservice接口)
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealAccuUseQry(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		logger.info("start dealAccuUseQry......");
		// 校验请求头
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");

        String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		logger.info("=========================CTGRequestID:"+CTGRequestID);
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QryCustBill");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null ) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getString("accNbr"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}

		JSONObject jsonContent = JSON.parseObject(content);
        jsonContent.put("CTGRequestID", CTGRequestID);
        LOG.info("start send webservice-----");
		String AccNbr =  jsonContent.getString("accNbr");// 电话号码(当用户属性为固话、小灵通、宽带时，此AVP取值要求带区号,含0)目前只提供手机查询
		String DestinationAttr = jsonContent.getString("destinationAttr");// 用户属性：0固话、1小灵通、2移动、3ADSL
		String ProductOfferId = jsonContent.getString("offerId");// 查询销售品标识（无此AVP时表示查询所有销售品）
		String BillingCycle = jsonContent.getString("billingCycle"); // 查询帐期（无此AVP时表示查当前帐期）
		if(StringUtils.isEmpty(BillingCycle)){
			BillingCycle = new SimpleDateFormat("yyyyMM").format(System.currentTimeMillis());
			jsonContent.put("billingCycle", BillingCycle);
		}
        String jf3_flag=userResourceConfigService.getValue("jf3_flag", "0");
        String jf3_ratable_flag=userResourceConfigService.getValue("jf3_ratable_flag", "0");
        String buildStringMes;
        LOG.info("=====================jf3_flag============"+jf3_flag);
        LOG.info("=====================jf3_ratable_flag============"+jf3_ratable_flag);
        jsonContent.put("jf3_ratable_flag",jf3_ratable_flag);
        jsonContent.put("reqSessionId",CTGRequestID);
        if(jf3_ratable_flag.equals("0")){
            LOG.info("=====================进入老流程入参============");
            LOG.info("start webservice-----");
             buildStringMes = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://server.ratable.asiainfo.com/\">"
                    + "<soapenv:Header/><soapenv:Body><ser:queryRatable>"
                    + "<param><![CDATA[<query from='212'>"
                    + "<AccNbr>" + AccNbr + "</AccNbr>"
                    + "<DestinationAttr>" + DestinationAttr + "</DestinationAttr>"
                    + "<BillingCycle>" + BillingCycle + "</BillingCycle>"
                    + "<ProductOfferId>" + ProductOfferId + "</ProductOfferId>"
                    + "</query>]]></param>"
                    + "</ser:queryRatable></soapenv:Body></soapenv:Envelope>";
            LOG.info("buildStringMes------" + buildStringMes);
        }else{
            LOG.info("=====================进入新流程入参============");
            jsonContent.put("jf3_flag",jf3_flag);
            buildStringMes = jsonContent.toString();
        }


		XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSIG(null);
        req.setSCID("AccuUseQry.NEW.JF3@027.ctnbc-bon.net");
		req.setREPTAG(0);
		req.setDATA(buildStringMes);
        jsonContent.put("jfStartTime", System.currentTimeMillis());
		// new CallParam对象
		AccuUseQryHandle accuUseQryHandle = new AccuUseQryHandle(body, jsonContent,request,startTime);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), accuUseQryHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
        long endTime = Calendar.getInstance().getTimeInMillis();
        String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("===session_id:"+CTGRequestID
                +"====recv_request_time:"+startDate
                +"====send_response_time:"+endDate
                +"====service_context_id:"+request.getPath().getPath()
                +"====访问时间差:"+(endTime-startTime));
	}

	
	/**
	 * 3.2.5 4.3.1.2.4 量本使用详情查询(下游webservice接口)
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealAccuUseDetailQry(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		logger.info("start dealAccuUseDetailQry......");
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============CTGRequestID:"+CTGRequestID);
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/AccuUseDetailQry");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getString("accNbr")) || StringUtils.isBlank(JSON.parseObject(content).getString("offerInstId"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}

		JSONObject jsonContent = JSON.parseObject(content);
        jsonContent.put("reqSessionId",CTGRequestID);
		String AccNbr = jsonContent.getString("accNbr");// 电话号码(当用户属性为固话、小灵通、宽带时，此AVP取值要求带区号,含0)目前只提供手机查询
		String queryFlag =jsonContent.getString("queryFlag");// 查询业务类型
		String destinstionAttr =jsonContent.getString("destinstionAttr");// 用户属性：0固话、1小灵通、2移动、3ADSL
//		String ProductOfferId =""; // 查询销售品标识（无此AVP时表示查询所有销售品）
		String BillingCycle =jsonContent.getString("billingCycle"); // 查询帐期（无此AVP时表示查当前帐期
		if(StringUtils.isEmpty(BillingCycle)){
			BillingCycle = new SimpleDateFormat("yyyyMM").format(System.currentTimeMillis());
			jsonContent.put("billingCycle", BillingCycle);
		}
		String ProdOfferInstanceId =jsonContent.getString("offerInstId"); // 查询销售品实例标识

		StringBuilder buildStringMes = new StringBuilder();
        String jf3_ratable_flag=userResourceConfigService.getValue("jf3_ratable_flag", "0");
        LOG.info("=============jf3_ratable_flag========="+jf3_ratable_flag);
        if(jf3_ratable_flag.equals("0")){
            LOG.info("============进入老程序入参=============");
            LOG.info("start webservice-----");
            buildStringMes.append(
                    "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://server.ratable.asiainfo.com/\">");
            buildStringMes.append("<soapenv:Header/>");
            buildStringMes.append("<soapenv:Body>");
            buildStringMes.append("<ser:queryRatableDetail>");
            buildStringMes.append("<param>");
            buildStringMes.append("<![CDATA[");
            buildStringMes.append("<query from='212'>");
            buildStringMes.append("<AccNbr>"+AccNbr+"</AccNbr>");
            buildStringMes.append("<DestinationAttr>"+destinstionAttr+"</DestinationAttr>");
            buildStringMes.append("<BillingCycle>"+BillingCycle+"</BillingCycle>");
            buildStringMes.append("<ProdOfferInstanceId>"+ProdOfferInstanceId+"</ProdOfferInstanceId>");
            buildStringMes.append("<QueryFlag>"+queryFlag+"</QueryFlag>");
            buildStringMes.append("</query>");
            buildStringMes.append("]]>");
            buildStringMes.append("</param>");
            buildStringMes.append("</ser:queryRatableDetail>");
            buildStringMes.append("</soapenv:Body>");
            buildStringMes.append("</soapenv:Envelope>");
            LOG.info("buildStringMes------" + buildStringMes.toString());
        }else{
            LOG.info("============进入新程序入参=============");
            buildStringMes.append(jsonContent.toString());
        }


		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("0".equals(jf3_ratable_flag)? "AccuUseDetailQry.NEW@027.ctnbc-bon.net":"AccuUseDetailQry.NEW.JF3@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(buildStringMes.toString());
		// new CallParam对象
		AccuUseDetailQryHandle accuUseDetailQryHandle = new AccuUseDetailQryHandle(body,request,startTime,jsonContent);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), accuUseDetailQryHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
        long endTime = Calendar.getInstance().getTimeInMillis();
        String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("===session_id:"+CTGRequestID
                +"====recv_request_time:"+startDate
                +"====send_response_time:"+endDate
                +"====service_context_id:"+request.getPath().getPath()
                +"====访问时间差:"+(endTime-startTime));
	}

	
	/**
	 * 余额查询(下游DCC+新增webservice接口)
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQueryBalance(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		logger.info("start dealQueryBalance......");
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============CTGRequestID:"+CTGRequestID);
        response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QueryBalance");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getJSONObject("svcObjectStruct").getString("objValue"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}

		JSONObject jsonObject = JSONObject.parseObject(content);
		jsonObject.put("YECXURLWH", whConfigService.getValue("YECXURLWH", null));
		jsonObject.put("YECXURLHB", whConfigService.getValue("YECXURLHB", null));
		String objType = jsonObject.getJSONObject("svcObjectStruct").getString("objType");
		String objValue = jsonObject.getJSONObject("svcObjectStruct").getString("objValue");
		String objAttr = jsonObject.getJSONObject("svcObjectStruct").getString("objAttr");
		String dataArea = jsonObject.getJSONObject("svcObjectStruct").getString("dataArea");
        Element serviceInformation = null;
        XmlMessage req = new XmlMessage(true);
        String IP = request.getClientAddress().getAddress().getHostAddress();
        String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
        String sessionId = DiameterUtils.makeSessionID(tmallHostId);
        req.setIp(IP);
        req.setMsgTime(receiveTime);
        req.setMID(sessionId);
        req.setUID(tmallHostId);
        req.setSCID("QueryBalance.NEW.JF3@027.ctnbc-bon.net");//去鉴权
        req.setSIG(null);
        req.setREPTAG(0);
        req.setDATA("");
		// new CallParam对象
		jsonObject.put("IP", IP);
		QueryBalanceHandle2 qBalanceHandle = new QueryBalanceHandle2(body, jsonObject,request,startTime);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), qBalanceHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
        long endTime = Calendar.getInstance().getTimeInMillis();
        String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("===session_id:"+CTGRequestID
                +"====recv_request_time:"+startDate
                +"====send_response_time:"+endDate
                +"====service_context_id:"+request.getPath().getPath()
                +"====访问时间差:"+(endTime-startTime));
	}
	
	/**
	 * 实时话费明细查询
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void delQryInstantFeeList(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
        Map<String, String> data = new HashMap<String, String>();
        try {
            logger.info("start delQryInstantFeeList......");
            // 校验请求头
            String method = request.getMethod();
            String contentType = request.getValue("Content-Type");
            String CTGRequestID = request.getValue("X-CTG-Request-ID");
            long startTime = Calendar.getInstance().getTimeInMillis();
            String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
            logger.info("=============CTGRequestID:"+CTGRequestID);
            response.set("Content-Type", "application/json;charset=utf-8");
            response.set("Location", "/QryCustBill");
            response.set("X-CTG-Request-ID", CTGRequestID);
            response.set("X-RateLimit-Limit", "60");
            response.set("X-RateLimit-Remaining", "48");
            response.set("X-RateLimit-Reset", "14");
            if (!"POST".equals(method)) {
                data.put("resultCode", "01");
                data.put("resultMsg", "该接口只支持POST提交");
                Gson gson = new Gson();
                String respXML = gson.toJson(data);
                byte[] resp = respXML.getBytes("UTF-8");
                body.write(resp);
                body.close();
                return;
            }
            String content = request.getContent();
            JSONObject jsonContent = JSON.parseObject(content);
            String billingCycleId = jsonContent.getString("billingCycleId");

            // 入参校验
            String date = DateUtil.DateToStr(new Date(), "yyyyMM");
            if(!date.equals(billingCycleId)){
                //非当前期次
                String newCode = ResultCodeUtil.updateResultCode("7003", userResourceConfigService.getValue("api_resultCode"), userResourceConfigService.getValue("api_defaultResult"));
                data.put("resultCode", newCode);
                data.put("resultMsg", "非当前账期");
                Gson gson = new Gson();
                String respXML = gson.toJson(data);
                byte[] resp = respXML.getBytes("UTF-8");
                body.write(resp);
                body.close();
                return;
            }


            String objAttr = jsonContent.getJSONObject("svcObjectStruct").getString("objAttr");
            String objValue = jsonContent.getJSONObject("svcObjectStruct").getString("objValue");
            String objType = jsonContent.getJSONObject("svcObjectStruct").getString("objType");
            String dataArea = jsonContent.getJSONObject("svcObjectStruct").getString("dataArea");
            String str;
            String Query_Flag= "2".equals(dataArea)?"1":"0";
            if("2".equals(objAttr) || "6".equals(objAttr) || "027".equals(objValue.substring(0,3))){
                str="027";
            }else{
                str=objValue.substring(0,4);
            }
            Element serviceInformation = DocumentHelper.createElement("Service_Information");
            serviceInformation.addElement("Channel_Id").setText("0");
            serviceInformation.addElement("Area_Code").setText(str);
            serviceInformation.addElement("DestinationAttr").setText(objAttr);
            serviceInformation.addElement("Destination_Id").setText(objValue);
            serviceInformation.addElement("Destination_Id_Type").setText("2");
            serviceInformation.addElement("Query_Flag").setText(Query_Flag);
            serviceInformation.addElement("Billing_Cycle").setText(billingCycleId);

            XmlMessage req = new XmlMessage(true);
            // 定义橙分期HOST ID
            String IP = request.getClientAddress().getAddress().getHostAddress();
            String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
            String sessionId = DiameterUtils.makeSessionID(tmallHostId);
            req.setIp(IP);
            req.setMsgTime(receiveTime);
            req.setMID(sessionId);
            req.setUID(tmallHostId);
            req.setSCID("RealFeeQuery.jf3@027.ctnbc-bon.net");
            req.setSIG(null);
            req.setREPTAG(0);
            req.setDATA(serviceInformation.asXML());
            req.setDataElement(serviceInformation);
            logger.info("======serviceInformation:"+serviceInformation.asXML());
            QryInstantFeeListHandle qryInstantFeeListHandle = new QryInstantFeeListHandle(body,request,startTime,jsonContent);
            CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), qryInstantFeeListHandle);
            BuzProcessorManager.getInstance().processRequest(callParam);

            long endTime = Calendar.getInstance().getTimeInMillis();
            String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
            logger.info("===session_id:"+CTGRequestID
                    +"====recv_request_time:"+startDate
                    +"====send_response_time:"+endDate
                    +"====service_context_id:"+request.getPath().getPath()
                    +"====访问时间差:"+(endTime-startTime));
        }catch (Exception e){
            logger.error("==========delQryInstantFeeList.Exception:",e);
            data.put("resultCode", "-1");
            data.put("resultMsg", "系统错误!");
            Gson gson = new Gson();
            String respXML = gson.toJson(data);
            byte[] resp = respXML.getBytes("UTF-8");
            body.write(resp);
            body.close();
            return;
        }

	}
	/**
	 * 3.2.11.1欠费查询API
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQryBill(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		logger.info("start dealQryBill......");
        logger.info("start HBCFQChannel_QryBill.dealQryBill ......");
        // 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============CTGRequestID:"+CTGRequestID);
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QryBill");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getString("destinationAccount"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}

		JSONObject jsonObject = JSONObject.parseObject(content);
		jsonObject.put("YECXURLWH", whConfigService.getValue("YECXURLWH", null));
		jsonObject.put("YECXURLHB", whConfigService.getValue("YECXURLHB", null));
		
		jsonObject.put("YECXURLWHjf3", whConfigService.getValue("YECXURLWHjf3", null));
		jsonObject.put("YECXURLHBjf3", whConfigService.getValue("YECXURLHBjf3", null));
		String objValue = jsonObject.getString("destinationAccount");
		String destinationAttr = jsonObject.getString("destinationAttr");
		Element serviceInformation = null;
		String jf3_flag=userResourceConfigService.getValue("jf3_flag", "0");
			//开关开,调用新流程
			String substring = objValue.substring(0, 1);
			String str = null; 
			if("1".equals(substring)) {
				str="027";
			}else if("0".equals(substring)) {
				str=objValue.substring(0, 3);
				if(!"027".equals(str)) {
					str=objValue.substring(0, 4);
				}
			}else if("6".equals(destinationAttr)){
                //天翼高清
                str="0"+objValue.substring(0, 3);
            }else{
                str="027";
            }
			serviceInformation = DocumentHelper.createElement("Service_Information");
			serviceInformation.addElement("Channel_Id").setText("200");
			serviceInformation.addElement("Area_Code").setText(str);
			serviceInformation.addElement("DestinationAttr").setText(destinationAttr);
			serviceInformation.addElement("Destination_Id").setText(objValue);
			serviceInformation.addElement("Destination_Id_Type").setText("2");
        String qrybil_dcc_request = userResourceConfigService.getValue("qrybil_dcc_request");
        XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("1".equals(qrybil_dcc_request) ? "QueryBalance.NEW.JF3@027.ctnbc-bon.net": "ServAuth.jf3@027.ctnbc-bon.net"  );
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(serviceInformation.asXML());
		req.setDataElement(serviceInformation);
        jsonObject.put("jfStartTime", System.currentTimeMillis());
        jsonObject.put("qrybil_dcc_request",qrybil_dcc_request);
		// new CallParam对象
		QryBillHandle qryBillHandle = new QryBillHandle(body, jsonObject,request,startTime);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), qryBillHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);

    }
	
	
	/**
	 * 3.2.12.1缴费销帐记录查询API
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQryPayment(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		logger.info("start dealQryPayment......");
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============CTGRequestID:"+CTGRequestID);
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QryPayment");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null ) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getJSONObject("svcObjectStruct").getString("objValue")) || StringUtils.isBlank(JSON.parseObject(content).getString("billingCycleId"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}

		JSONObject jsonObject = JSONObject.parseObject(content);
		jsonObject.put("YECXURLWH", whConfigService.getValue("YECXURLWH", null));
		jsonObject.put("YECXURLHB", whConfigService.getValue("YECXURLHB", null));
		jsonObject.put("YECXURLWHjf3", whConfigService.getValue("YECXURLWHjf3", null));
		jsonObject.put("YECXURLHBjf3", whConfigService.getValue("YECXURLHBjf3", null));
		String objType = jsonObject.getJSONObject("svcObjectStruct").getString("objType");
		String objValue = jsonObject.getJSONObject("svcObjectStruct").getString("objValue");
		String objAttr = jsonObject.getJSONObject("svcObjectStruct").getString("objAttr");
		String dataArea = jsonObject.getJSONObject("svcObjectStruct").getString("dataArea");

		XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("QueryBalance.NEW.JF3@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA("");
		// new CallParam对象
		QryPaymentHandle qryBillHandle = new QryPaymentHandle(body, jsonObject,request,startTime);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), qryBillHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
        long endTime = Calendar.getInstance().getTimeInMillis();
        String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("===session_id:"+CTGRequestID
                +"====recv_request_time:"+startDate
                +"====send_response_time:"+endDate
                +"====service_context_id:"+request.getPath().getPath()
                +"====访问时间差:"+(endTime-startTime));
	}
	
	
	/**
	 * 3.2.134.5.1.2.1.	余额变动明细查询 (下游DCC+新增webservice接口)
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQryBalanceRecordDetail(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		logger.info("start QryBalanceRecordDetail......");
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
        long startTime = Calendar.getInstance().getTimeInMillis();
        String startDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("=============CTGRequestID:"+CTGRequestID);
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QryBalanceRecordDetail");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		try {
			if(StringUtils.isBlank(JSON.parseObject(content).getJSONObject("svcObjectStruct").getString("objValue")) || StringUtils.isBlank(JSON.parseObject(content).getString("billingCycleId"))) {
				throw new Exception();
			}
		}catch (Exception e) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}

		JSONObject jsonObject = JSONObject.parseObject(content);
		jsonObject.put("YECXURLWH", whConfigService.getValue("YECXURLWH", null));
		jsonObject.put("YECXURLHB", whConfigService.getValue("YECXURLHB", null));
		String objType = jsonObject.getJSONObject("svcObjectStruct").getString("objType");
		String objValue = jsonObject.getJSONObject("svcObjectStruct").getString("objValue");
		String objAttr = jsonObject.getJSONObject("svcObjectStruct").getString("objAttr");
		String dataArea = jsonObject.getJSONObject("svcObjectStruct").getString("dataArea");
		Element serviceInformation = null;
		String jf3_flag=userResourceConfigService.getValue("jf3_flag", "0");
		jsonObject.put("jf3_flag", jf3_flag);
		logger.info("=========================jf3_flag=============="+jf3_flag);
		if("1".equals(jf3_flag)) {
			logger.info("==============进入新流程==============");
			//开关开,调用新流程
			String substring = objValue.substring(0, 1);
			String str = null; 
			if("1".equals(substring)) {
				str="027";
			}else if("0".equals(substring)) {
				str=objValue.substring(0, 3);
				if(!"027".equals(str)) {
					str=objValue.substring(0, 4);
				}
			}else if("6".equals(objAttr)){
                //天翼高清
                str="0"+objValue.substring(0, 3);
            }else{
                str="027";
            }
			serviceInformation = DocumentHelper.createElement("Service_Information");
			serviceInformation.addElement("Channel_Id").setText("200");
			serviceInformation.addElement("Area_Code").setText(str);
			serviceInformation.addElement("DestinationAttr").setText(objAttr);
			serviceInformation.addElement("Destination_Id").setText(objValue);
			serviceInformation.addElement("Destination_Id_Type").setText("2");
		}else {
			logger.info("==============进入旧流程==============");
			//开关 关,旧流程
			serviceInformation = DocumentHelper.createElement("Service_Information");
			serviceInformation.addElement("Acc_Nbr").setText(jsonObject.getJSONObject("svcObjectStruct").get("objValue")+"");//电话号码  取入参objValue
			serviceInformation.addElement("Destination_Attr").setText("2".equals(jsonObject.getJSONObject("svcObjectStruct").get("objAttr")) ? "2" : "0");//被充值用户属性（当号码类型为用户号码时用户号码时填写）
		}
		XmlMessage req = new XmlMessage(true);
		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("1".equals(jf3_flag) ? "ServAuth.jf3@027.ctnbc-bon.net" : "QueryHomeAreaByAccNbr.HSS@027.ctnbc-bon.net");
		req.setSIG(null);
		req.setREPTAG(0);
		req.setDATA(serviceInformation.asXML());
		req.setDataElement(serviceInformation);
		jsonObject.put("IP", IP);
		// new CallParam对象
		QryBalanceRecordDetailHandle qryBalanceRecordDetailHandle = new QryBalanceRecordDetailHandle(body, jsonObject,request,startTime);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), qryBalanceRecordDetailHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
        long endTime = Calendar.getInstance().getTimeInMillis();
        String endDate = DateUtil.DateToStr(new Date(), "yyyy-MM-dd HH:mm:ss SSSS");
        logger.info("===session_id:"+CTGRequestID
                +"====recv_request_time:"+startDate
                +"====send_response_time:"+endDate
                +"====service_context_id:"+request.getPath().getPath()
                +"====访问时间差:"+(endTime-startTime));
	}
	
	/**
	 * 5G入网提醒API接口
	 * 
	 *
	 */
	protected void dealImeiInfo(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		logger.info("start dealAccuUseDetailQry......");
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		String CTGProvinceID = request.getValue("X-CTG-Province-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/AccuUseDetailQry");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-CTG-Province-ID", CTGProvinceID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			Gson gson = new Gson();
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
//		try {
//			if(StringUtils.isBlank(JSON.parseObject(content).getString("accNbr")) || StringUtils.isBlank(JSON.parseObject(content).getString("offerInstId"))) {
//				throw new Exception();
//			}
//		}catch (Exception e) {
//			data.put("resultCode", "1001");
//			data.put("resultMsg", "参数缺失");
//			Gson gson = new Gson();
//			String respXML = gson.toJson(data);
//			byte[] resp = respXML.getBytes("UTF-8");
//			body.write(resp);
//			body.close();
//			return;
//		}
//		if (content == null || "".equals(content)) {
//			data.put("resultCode", "1001");
//			data.put("resultMsg", "参数缺失");
//			Gson gson = new Gson();
//			String respXML = gson.toJson(data);
//			byte[] resp = respXML.getBytes("UTF-8");
//			body.write(resp);
//			body.close();
//			return;
//		}

		//JSONObject jsonContent = JSON.parseObject(content);
		LOG.info("start send webservice-----");
		List<JSONObject> imeiInfoList = JSONObject.parseArray(content, JSONObject.class);
		StringBuilder buildStringMes = new StringBuilder();
		LOG.info("start webservice-----");
		buildStringMes.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.WSSInterface.crm.tydic.com\">\r\n" + 
				"   <soapenv:Header/>\r\n" + 
				"   <soapenv:Body>\r\n" + 
				"      <ser:callService>\r\n" + 
				"         <ser:in0><![CDATA[");
		for (JSONObject jsonObject : imeiInfoList) {
			buildStringMes.append("<ESB>\r\n" + 
					"  <SERVICE_CD>REGISTSEND</SERVICE_CD>\r\n" + 
					"  <mdn>"+jsonObject.getString("mdn")+"</mdn>\r\n" + 
					"  <imei>"+jsonObject.getString("imei")+"</imei>\r\n" + 
					"  <messageId>"+jsonObject.getString("messageId")+"</messageId>\r\n" + 
					"  <model>"+jsonObject.getString("model")+"</model>\r\n" + 
					"<provinceId>"+jsonObject.getString("provinceId")+"</provinceId>\r\n" + 
					"<5gFlag>"+jsonObject.getString("5gFlag")+"</5gFlag>\r\n" + 
					"</ESB>");
		}
		buildStringMes.append(" ]]></ser:in0>\r\n" + 
				"      </ser:callService>\r\n" + 
				"   </soapenv:Body>\r\n" + 
				"</soapenv:Envelope>");
		LOG.info("buildStringMes------" + buildStringMes.toString());

		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicWebService.NEW@027.ctnbc-bon.net");
		req.setSIG(whConfigService.getValue("RWTX_5G", null) );
		req.setREPTAG(0);
		req.setDATA(buildStringMes.toString());
		// new CallParam对象
		ImeiInfoHandle imeiInfoHandle = new ImeiInfoHandle(body);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), imeiInfoHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	/**
	 * 3.3.1 4.5.1.2.8. 帐本变更信息查询(下游数据库直连)
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQryBalanceModifyLog(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 查询客户历史帐单的服务 add by fengr 20190705
		logger.info("start dealQryCustBill......");
		Gson gson = new Gson();
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QryBalanceModifyLog");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		if (content == null || "".equals(content)) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicAndAbm.NEW@027.ctnbc-bon.net");
		req.setSIG("1");//用于SIDAndAbmServiceProcessor 识别接口
		req.setREPTAG(0);
		req.setDATA(content);
		// new CallParam对象
		QryBalanceModifyLogHandle qryBalanceModifyLogHandle = new QryBalanceModifyLogHandle(body,JSONObject.parseObject(content));
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), qryBalanceModifyLogHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}

	/**
	 * 3.3.2 4.5.6.2.2 增值税查询(下游数据库直连)
	 * @param request
	 * @param response
	 * @param body
	 * @param receiveTime
	 * @throws Exception
	 */
	protected void dealQryTax(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 查询客户历史帐单的服务 add by fengr 20190705
		logger.info("start dealQryTax......");
		Gson gson = new Gson();
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/QryTax");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if (!"POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持POST提交");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		String content = request.getContent();
		// 入参校验
		if (content == null || "".equals(content)) {
			data.put("resultCode", "1001");
			data.put("resultMsg", "参数缺失");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}

		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicAndAbm.NEW@027.ctnbc-bon.net");
		req.setSIG("2");//用于SIDAndAbmServiceProcessor 识别接口
		req.setREPTAG(0);
		req.setDATA(content);
		// new CallParam对象
		QryTaxHandle qryTax = new QryTaxHandle(body, JSONObject.parseObject(content));
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), qryTax);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	
	/**
	 * 查询余额详情  /balance/{acctBalanceId}
	 * 查询余额列表 /balance
	 * 
	 *
	 */
	protected void dealBalance(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		logger.info("start dealBalance......");
		Gson gson = new Gson();
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/balance");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if ("POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持GET提交");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		
		//初始化参数
		Map<String, Object> contentMap=new HashMap<String, Object>();
		String content="";
		int isOne=0;
		String reqPath = request.getPath().getPath();
		JSONObject contentObject = null;
		if(reqPath.contains("/balance/")) {
			//详情
			String acctBalanceId=reqPath.substring(reqPath.lastIndexOf("/")+1);
			contentMap.put("acctBalanceId", acctBalanceId);
			contentMap.put("isOne", isOne);
			// 入参校验 acctBalanceId 
			if (StringUtils.isBlank(acctBalanceId)) {
				data.put("resultCode", "1001");
				data.put("resultMsg", "参数缺失");
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
		}else {
			// 入参校验
			 content = request.getContent();
			  contentObject = JSONObject.parseObject(content);
			if(StringUtils.isBlank(contentObject.getString("acctBalanceId")) && StringUtils.isBlank(contentObject.getString("acctId"))) {
				data.put("resultCode", "1001");
				data.put("resultMsg", "参数缺失");
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
			isOne=1;
		}
		
		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicAndAbm.NEW@027.ctnbc-bon.net");
		req.setSIG("3");//用于SIDAndAbmServiceProcessor 识别接口
		req.setREPTAG(0);
		req.setDATA(isOne == 0? new JSONObject(contentMap).toString() : content);
		// new CallParam对象
		BalanceHandle2 balanceHandle2 = new BalanceHandle2(body, isOne == 0? new JSONObject( contentMap ):contentObject);
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), balanceHandle2);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	
	
	/**
	 * 查询余额帐本类型详情  /balanceType/{balanceTypeId}
	 * 查询余额帐本类型列表  /balanceType
	 * 
	 *
	 */
	protected void dealBalanceType(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 查询客户历史帐单的服务 add by fengr 20190705
		logger.info("start dealBalanceType......");
		Gson gson = new Gson();
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/BalanceType");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if ("POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持GET提交");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		//初始化参数
		
		Map<String, Object> contentMap=new HashMap<String, Object>();
		String content="";
		int isOne=0;
		String reqPath = request.getPath().getPath();
		if(reqPath.contains("/balanceType/")) {
			//详情
			String balanceTypeId=reqPath.substring(reqPath.lastIndexOf("/")+1);
			contentMap.put("balanceTypeId", balanceTypeId);
			contentMap.put("isOne", isOne);
			// 入参校验 balanceTypeId 
			if (StringUtils.isBlank(balanceTypeId)) {
				data.put("resultCode", "1001");
				data.put("resultMsg", "参数缺失");
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
		}else {
			 content = request.getContent();
			if(StringUtils.isBlank(content)) {
				data.put("resultCode", "1001");
				data.put("resultMsg", "参数缺失");
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
			isOne=1;
		}


		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicAndAbm.NEW@027.ctnbc-bon.net");
		req.setSIG("4");//用于SIDAndAbmServiceProcessor 识别接口
		req.setREPTAG(0);
		req.setDATA(isOne == 0? new JSONObject(contentMap).toString() : content);
		// new CallParam对象
		BalanceTypeHandle balanceTypeHandle = new BalanceTypeHandle(body, isOne == 0? new JSONObject( contentMap ):JSONObject.parseObject(content));
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), balanceTypeHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	
	/**
	 * 查询付款方式详情 
	 * 查询付款方式列表
	 * paymentMethod
	 * 
	 *
	 */
	protected void dealPaymentMethod(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 查询客户历史帐单的服务 add by fengr 20190705
		logger.info("start dealPaymentMethod......");
		Gson gson = new Gson();
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/paymentMethod");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if ("POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持GET提交");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		//初始化参数
		
		Map<String, Object> contentMap=new HashMap<String, Object>();
		String content="";
		int isOne=0;
		String reqPath = request.getPath().getPath();
		if(reqPath.contains("/paymentMethod/")) {
			//详情
			String balanceTypeId=reqPath.substring(reqPath.lastIndexOf("/")+1);
			contentMap.put("paymentMethod", balanceTypeId);
			contentMap.put("isOne", isOne);
			// 入参校验 balanceTypeId 
			if (StringUtils.isBlank(balanceTypeId)) {
				data.put("resultCode", "1001");
				data.put("resultMsg", "参数缺失");
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
		}else {
			 content = request.getContent();
//			if(StringUtils.isBlank(content)) {
//				data.put("resultCode", "1001");
//				data.put("resultMsg", "参数缺失");
//				String respXML = gson.toJson(data);
//				byte[] resp = respXML.getBytes("UTF-8");
//				body.write(resp);
//				body.close();
//				return;
//			}
			isOne=1;//未进入参数传递
		}


		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicAndAbm.NEW@027.ctnbc-bon.net");
		req.setSIG("5");//用于SIDAndAbmServiceProcessor 识别接口
		req.setREPTAG(0);
		req.setDATA(isOne == 0? new JSONObject(contentMap).toString() : content);
		// new CallParam对象
		PublicBusinessHandle publicBusinessHandle = new PublicBusinessHandle(body, isOne == 0? new JSONObject( contentMap ):JSONObject.parseObject(content));
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), publicBusinessHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	
	/**
	 * 查询帐目类型详情
	 * 查询帐目类型列表
	 * acctItemType
	 * 
	 *
	 */
	protected void dealAcctItemType(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 查询客户历史帐单的服务 add by fengr 20190705
		logger.info("start dealAcctItemType......");
		Gson gson = new Gson();
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/acctItemType");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if ("POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持GET提交");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		//初始化参数
		
		Map<String, Object> contentMap=new HashMap<String, Object>();
		String content="";
		int isOne=0;
		String reqPath = request.getPath().getPath();
		if(reqPath.contains("/acctItemType/")) {
			//详情
			String balanceTypeId=reqPath.substring(reqPath.lastIndexOf("/")+1);
			contentMap.put("acctItemTypeId", balanceTypeId);
			contentMap.put("isOne", isOne);
			// 入参校验 balanceTypeId 
			if (StringUtils.isBlank(balanceTypeId)) {
				data.put("resultCode", "1001");
				data.put("resultMsg", "参数缺失");
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
		}else {
			 content = request.getContent();
//			if(StringUtils.isBlank(content)) {
//				data.put("resultCode", "1001");
//				data.put("resultMsg", "参数缺失");
//				String respXML = gson.toJson(data);
//				byte[] resp = respXML.getBytes("UTF-8");
//				body.write(resp);
//				body.close();
//				return;
//			}
//			isOne=1;
		}


		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicAndAbm.NEW@027.ctnbc-bon.net");
		req.setSIG("6");//用于SIDAndAbmServiceProcessor 识别接口
		req.setREPTAG(0);
		req.setDATA(isOne == 0? new JSONObject(contentMap).toString() : content);
		// new CallParam对象
		PublicBusinessHandle publicBusinessHandle = new PublicBusinessHandle(body, isOne == 0? new JSONObject( contentMap ):JSONObject.parseObject(content));
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), publicBusinessHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	
	/**
	 * 查询税目详情
	 * 查询税目列表
	 * taxItem
	 * 
	 *
	 */
	protected void dealTaxItem(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 查询客户历史帐单的服务 add by fengr 20190705
		logger.info("start dealTaxItem......");
		Gson gson = new Gson();
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/taxItem");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if ("POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持GET提交");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		//初始化参数
		
		Map<String, Object> contentMap=new HashMap<String, Object>();
		String content="";
		int isOne=0;
		String reqPath = request.getPath().getPath();
		if(reqPath.contains("/taxItem/")) {
			//详情
			String balanceTypeId=reqPath.substring(reqPath.lastIndexOf("/")+1);
			contentMap.put("taxItemId", balanceTypeId);
			contentMap.put("isOne", isOne);
			// 入参校验 balanceTypeId 
			if (StringUtils.isBlank(balanceTypeId)) {
				data.put("resultCode", "1001");
				data.put("resultMsg", "参数缺失");
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
		}else {
			 content = request.getContent();
//			if(StringUtils.isBlank(content)) {
//				data.put("resultCode", "1001");
//				data.put("resultMsg", "参数缺失");
//				String respXML = gson.toJson(data);
//				byte[] resp = respXML.getBytes("UTF-8");
//				body.write(resp);
//				body.close();
//				return;
//			}
			isOne=1;
		}


		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicAndAbm.NEW@027.ctnbc-bon.net");
		req.setSIG("7");//用于SIDAndAbmServiceProcessor 识别接口
		req.setREPTAG(0);
		req.setDATA(isOne == 0? new JSONObject(contentMap).toString() : content);
		// new CallParam对象
		PublicBusinessHandle publicBusinessHandle = new PublicBusinessHandle(body, isOne == 0? new JSONObject( contentMap ):JSONObject.parseObject(content));
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), publicBusinessHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	/**
	 * 查询押金类型详情
	 * 查询押金类型列表
	 * depositType
	 */
	protected void dealDepositType(Request request, Response response, PrintStream body, long receiveTime) throws Exception {
		// 查询客户历史帐单的服务 add by fengr 20190705
		logger.info("start dealDepositType......");
		Gson gson = new Gson();
		// 校验请求头
		String method = request.getMethod();
		String contentType = request.getValue("Content-Type");
		String xAppId = request.getValue("X-APP-ID");
		String xAppKey = request.getValue("X-APP-KEY");
		String CTGRequestID = request.getValue("X-CTG-Request-ID");
		response.set("Content-Type", "application/json;charset=utf-8");
		response.set("Location", "/paymentMethod");
		response.set("X-CTG-Request-ID", CTGRequestID);
		response.set("X-RateLimit-Limit", "60");
		response.set("X-RateLimit-Remaining", "48");
		response.set("X-RateLimit-Reset", "14");
		Map<String, String> data = new HashMap<String, String>();
		if ("POST".equals(method)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "该接口只支持GET提交");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		if (xAppId == null || xAppKey == null || !"application/json".equals(contentType)) {
			data.put("resultCode", "01");
			data.put("resultMsg", "请求头信息错误");
			String respXML = gson.toJson(data);
			byte[] resp = respXML.getBytes("UTF-8");
			body.write(resp);
			body.close();
			return;
		}
		//初始化参数
		
		Map<String, Object> contentMap=new HashMap<String, Object>();
		String content="";
		int isOne=0;
		String reqPath = request.getPath().getPath();
		if(reqPath.contains("/depositType/")) {
			//详情
			String balanceTypeId=reqPath.substring(reqPath.lastIndexOf("/")+1);
			contentMap.put("depositTypeId", balanceTypeId);
			contentMap.put("isOne", isOne);
			// 入参校验 balanceTypeId 
			if (StringUtils.isBlank(balanceTypeId)) {
				data.put("resultCode", "1001");
				data.put("resultMsg", "参数缺失");
				String respXML = gson.toJson(data);
				byte[] resp = respXML.getBytes("UTF-8");
				body.write(resp);
				body.close();
				return;
			}
		}else {
			 content = request.getContent();
//			if(StringUtils.isBlank(content)) {
//				data.put("resultCode", "1001");
//				data.put("resultMsg", "参数缺失");
//				String respXML = gson.toJson(data);
//				byte[] resp = respXML.getBytes("UTF-8");
//				body.write(resp);
//				body.close();
//				return;
//			}
			isOne=1;
		}


		XmlMessage req = new XmlMessage(true);

		String IP = request.getClientAddress().getAddress().getHostAddress();
		String tmallHostId = "SGWHBCFQ@027.ctnbc-bon.net";
		String sessionId = DiameterUtils.makeSessionID(tmallHostId);
		req.setIp(IP);
		req.setMsgTime(receiveTime);
		req.setMID(sessionId);
		req.setUID(tmallHostId);
		req.setSCID("PublicAndAbm.NEW@027.ctnbc-bon.net");
		req.setSIG("8");//用于SIDAndAbmServiceProcessor 识别接口
		req.setREPTAG(0);
		req.setDATA(isOne == 0? new JSONObject(contentMap).toString() : content);
		// new CallParam对象
		PublicBusinessHandle publicBusinessHandle = new PublicBusinessHandle(body, isOne == 0? new JSONObject( contentMap ):JSONObject.parseObject(content));
		CallParam callParam = new CallParam(req.getMID(), req.getSCID(), req, req.getUID(), publicBusinessHandle);
		BuzProcessorManager.getInstance().processRequest(callParam);
	}
	
	
	
	
	
	
	
	

	protected void dealWithOtherReqPath(long reqTime, Request request, PrintStream body, String reqPath) throws Exception {
		body.println("No service provided at this address path ");
		body.close();
	}

	@Autowired
	public void setRsaSignService(RSASignService rsaSignService) {
		this.rsaSignService = rsaSignService;
	}

	public Set<String> monitorConfKeys() {
		return this.monitorConfKeys;
	}

	public void onConfigUpdated(String updatedKey) {
		loadParams();
	}

	private void loadParams() {
		this.maxLinkCount = this.confSrv.getIntValue("business.max_conn", 10000);
		logger.info("load param business.max_conn to value " + this.maxLinkCount);
	}

	public int sendRequest(CallParam callParam) {
		if (callParam.getToNode() != null) {
			SGWService sgwServiceClient = Comutils.getSGWServiceClient(callParam.getToNode().getServerUrl());

			if (sgwServiceClient == null) {
				callParam.setRetCode(11204);
				callParam.setResultMsg("wsclient is null");
				callParam.getAsynHandler().onCallResult(callParam);
				InprogressMessageQueue.getInstance().removeProgress(callParam.getMessageUniqueID());
				return -1;
			}

			SgwQueryReq sgwreq = new SgwQueryReq();
			sgwreq.setMID(callParam.getSessionId());
			sgwreq.setUID(callParam.getUserName());
			String pwd = callParam.getFromNode().getPassword();
			try {
				sgwreq.setPWD(pwd == null ? null : RSAUtil.getReadableMD5Data(pwd.getBytes("iso-8859-1")));
			} catch (UnsupportedEncodingException e1) {
				e1.printStackTrace();
			}
			sgwreq.setSCID(callParam.getServiceContextId());

			if ((callParam.getRequest() instanceof XmlMessage)) {
				sgwreq.setDATA(((XmlMessage) callParam.getRequest()).getDATA());
			} else if ((callParam.getRequest() instanceof Message)) {
				AVP sgwRootAVP = DccAvpHelper.createSGWRootAVPFromMessage((Message) callParam.getRequest());
				ProtocalConvertResult result = DataExchangerImpl.getInstance().convertFromCCRRequest(callParam.getServiceContextId(), sgwRootAVP);
				if (result.getRetCode() == 0) {
					sgwreq.setDATA(((Element) result.getResult()).asXML());
				} else {
					callParam.setRetCode(result.getRetCode());
					callParam.setResultMsg(result.getErrMsg());
					callParam.getAsynHandler().onCallResult(callParam);
					InprogressMessageQueue.getInstance().removeProgress(callParam.getMessageUniqueID());
					return -1;
				}
			}

			SgwQueryAck sgwAck = null;
			try {

				XmlMessage sendRequest = new XmlMessage(true);
				sendRequest.setMsgTime(System.currentTimeMillis());
				sendRequest.setMID(callParam.getSessionId());
				sendRequest.setSCID(callParam.getServiceContextId());
				sendRequest.setLength(sgwreq.getDATA().length());
				sendRequest.setDATA(sgwreq.getDATA());
				callParam.setSendRequest(sendRequest);

				sgwAck = sgwServiceClient.sgwQueryRequest(sgwreq);

				XmlMessage ack = new XmlMessage(false);
				ack.setMsgTime(System.currentTimeMillis());
				ack.setMID(sgwAck.getMID());
				ack.setSIG(sgwAck.getSIG());
				ack.setRC(sgwAck.getRC());
				ack.setDS(sgwAck.getDS());
				ack.setRTT(sgwAck.getRTT());
				ack.setREPTAG(sgwAck.getReptag());
				ack.setDATA(sgwAck.getDATA());
				try {
					if ((sgwAck.getDATA() != null) && (!"".equals(sgwAck.getDATA().toString()))) {
						Document doc = Comutils.parseText(sgwAck.getDATA());
						ack.setDataElement(doc.getRootElement());
					}
				} catch (Exception localException1) {
				}
				callParam.setRecvResponse(ack);

				int callRc = Integer.parseInt(sgwAck.getRC());
				callParam.setRetCode(callRc);
				callParam.setResultMsg(sgwAck.getDS());
			} catch (Exception e) {
				logger.warn("call ws service err:", e);
				int retCode = LogTool.getErrorCodeForBonCallException(e);
				callParam.setRetCode(retCode);
				callParam.setResultMsg("Call ws service err:" + e.getLocalizedMessage());
			}
			InprogressMessageQueue.getInstance().removeProgress(callParam.getMessageUniqueID());
			callParam.getAsynHandler().onCallResult(callParam);
		}

		return 0;
	}

	public SGWChannel getSGWChannel() {
		return this.channel;
	}

	public void stop() {
		logger.info("stop SoapChannel: " + this.channel.getChannelHost() + " ...");
		if (this.server != null) {
			try {
				this.server.stop();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		this.channel.setStatus(0);
		this.confSrv.updateChannelStatus2DB(this.channel.getId(), 0);
	}

	public void addPersist(Node node) {
	}

	public void deletePersist(Node node) {
	}

	public int getThreadPoolSize() {
		return this.executor.getPoolSize();
	}

	public int getThreadPoolQueueSize() {
		return this.executor.getQueue().size();
	}

	public int getNodeSendQueueSize(String nodeHostId) {
		return 0;
	}

	public int getThreadPoolActiveCount() {
		return this.executor.getActiveCount();
	}
	
	
	
	
	public static void main(String[] args) {//Jun 20, 2019
		System.out.println(JSONObject.parseObject("{\r\n" + 
				"	\"operAttrStruct\": {\r\n" + 
				"		\"staffId\": \"5001241181\",\r\n" + 
				"		\"operOrgId\": \"110\",\r\n" + 
				"		\"operTime\": \"20190425\",\r\n" + 
				"		\"operPost\": \"1\",\r\n" + 
				"		\"operServiceId\": \"1\",\r\n" + 
				"		\"lanId\": \"8340100\"\r\n" + 
				"	},\r\n" + 
				"	\"svcObjectStruct\": {\r\n" + 
				"		\"objType\": \"3\",  \r\n" + 
				"		\"objValue\": \"18986137973\",    \r\n" + 
				"		\"objAttr\": \"2\",    \r\n" + 
				"		\"dataArea\": \"1\"   \r\n" + 
				"	},\r\n" + 
				"	\"billingCycleId\": \"201906\"\r\n" + 
				"}"));
	}

}